package com.mk.datapower.controller;

import com.mk.datapower.annotation.APIDataPower;
import com.mk.datapower.bean.page.PageImpl;
import com.mk.datapower.bean.resp.MemberResp;
import com.mk.datapower.enums.ApiDataPowerMethodEnum;
import com.mk.datapower.enums.ApiDataPowerServerEnum;
import com.mk.datapower.enums.ApiDataPowerTableEnum;
import com.mk.datapower.util.ResponseUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: peisong.chen
 * @Date: 2019/9/16
 * @Content:
 */
@RestController
@RequestMapping("/data")
public class DataPowerController {

    @GetMapping("/hello")
    public void getDemo() {
        System.out.println("hello world");
    }

    /**
     * 模拟接口调用返回的数据(分页)
     * @return
     */
    @APIDataPower(source = ApiDataPowerServerEnum.CRM_SERVER, tableName = ApiDataPowerTableEnum.MEMBER_INFO, method = ApiDataPowerMethodEnum.LIST)
    @GetMapping("/getMemberInfoList")
    public ResponseUtil<List<MemberResp>> getMemberInfoList(){
        MemberResp memberResp = MemberResp.builder()
                .memberId("101")
                .phone("12323230987")
                .nickName("昵称~~")
                .cardNo("20190916")
                .sex("男")
                .registerTime(System.currentTimeMillis())
                .pointScore("199")
                .growthScore("1099")
                .build();
        List<MemberResp> memberRespList = new ArrayList<>();
        memberRespList.add(memberResp);

        return ResponseUtil.success(new PageImpl<>(memberRespList.size(),memberRespList));
    }

    /**
     * 模拟获取一个会员详情数据
     */
    @APIDataPower(source = ApiDataPowerServerEnum.CRM_SERVER, tableName = ApiDataPowerTableEnum.MEMBER_INFO, method = ApiDataPowerMethodEnum.DETAIL)
    @GetMapping("/getMemberDetail")
    public ResponseUtil<MemberResp> getMemberDetail(){
        MemberResp memberResp = MemberResp.builder()
                .memberId("101")
                .phone("12323230987")
                .nickName("昵称~~")
                .cardNo("20190916")
                .sex("男")
                .registerTime(System.currentTimeMillis())
                .pointScore("199")
                .growthScore("1099")
                .build();
        return ResponseUtil.success(memberResp);
    }
}